
#include <Inklude/ikCNetClientFactory.h>
#include <Windows.h>
#include <time.h>

using namespace Inklude;
int main(int argc, char* argv[])
{   
    // Create tcp async instance via factory class
    auto client = ikCNetClientFactory::CreateClient(Inklude::NET_OPTION::TCP_ASYNC);
    
    // The port number you put in here becomes the port a remote host can access.
    client->Initialize(9999);
    char *buffer = new char[60000];

    srand(time(NULL));

    // This is to make async handler function using lambda expression.
    // If you're not familiar to this expression, you can learn it
    // (a lot of resources on the web)
    // or just copy & paste is possible.
    ikINetClient::AsyncHandler handler;
    handler.reset(new std::function<void(size_t)>([&](size_t recvSize)
    {
        // In here, you can put what you want to do after receiving data.
        printf(buffer);
        // In here, just receive data.
        client->Receive(buffer, 6000, handler);
    }
    ));
    
    client->Receive(buffer, 6000, handler);

    // This is main thread code.
    // This is to maintain this thread (not for ending the app)
    while(true)
    {
        Sleep(1000);
        printf("This is main thread\n");
    }
	return 0;
}
